package com.java.time;

import java.time.Instant;
import java.time.ZoneId;

public class InstantAPI {
    public static void main(String[] args) {
        // now：当前时间时间戳 (世界标准时间)
        System.out.println(Instant.now()); // 2024-02-29T03:22:06.288Z
        
        // ofXxx：指定时间时间戳 (世界标准时间)
        System.out.println(Instant.ofEpochMilli(1000)); // 1970-01-01T00:00:01Z
        System.out.println(Instant.ofEpochSecond(2)); // 1970-01-01T00:00:02Z
        System.out.println(Instant.ofEpochSecond(3, 1000000000)); // 1970-01-01T00:00:04Z
        
        // atZone：指定时区的时间戳
        System.out.println(Instant.now().atZone(ZoneId.of("Asia/Shanghai"))); // 2024-02-29T11:22:06.335+08:00[Asia/Shanghai]
        
        // isXxx：判断时间的系列方法
        System.out.println(Instant.now().isBefore(Instant.ofEpochSecond(0))); // false
        System.out.println(Instant.now().isAfter(Instant.ofEpochSecond(0))); // true
        
        // plusXxx：增加时间的系列方法
        System.out.println(Instant.ofEpochSecond(30).plusNanos(1000000000)); // 1970-01-01T00:00:31Z
        System.out.println(Instant.ofEpochSecond(30).plusMillis(1000)); // 1970-01-01T00:00:31Z
        System.out.println(Instant.ofEpochSecond(30).plusSeconds(1)); // 1970-01-01T00:00:31Z
        
        // minusXxx：减少时间的系列方法
        System.out.println(Instant.ofEpochSecond(30).minusNanos(1000000000)); // 1970-01-01T00:00:29Z
        System.out.println(Instant.ofEpochSecond(30).minusMillis(1000)); // 1970-01-01T00:00:29Z
        System.out.println(Instant.ofEpochSecond(30).minusSeconds(1)); // 1970-01-01T00:00:29Z
    }
}
